<?php
require (Yii::app ()->basePath . '/lib/rolling-curl/RollingCurl.php');
/**
 *
 * @author Aptitude
 * @see 资质审核管理
 */
class AptitudeController extends CController {
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_3() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_3' );
	}
	/**
	 *
	 * @see 三级资质ajax列表
	 */
	function actionAjax_list_3_list() {
		$ret = new stdClass ();
		$ret->status = 401;
		/*
		 * if (Yii::app ()->user->isGuest) {
		 * $ret->data = "请登录";
		 * echo json_encode ( $ret );
		 * Yii::app ()->end ();
		 * }
		 */
		$service = new ReceiptEntity ();
		$pg = $_GET ['page'];
		$name = $_GET ['c_unit'];
		
		$where = array (
				'deleted' => 0,
				' ' => "[code] (content='三级新办' or content='三级延续') [code]" 
		);
		if ($name != "") {
			$where ['c_unit'] = "[code] like '%$name%' [code]";
		}
		$tb = $_GET ['tb'];
		switch ($tb) {
			default :
				break;
			case "1" :
				$where ['status'] = "提交初审";
				break;
			case "2" :
				$where ['status'] = "初审通过";
				break;
			case "3" :
				$where ['status'] = "初审退回";
				break;
			case "4" :
				$where ['status'] = "原件审核";
				break;
			case "5" :
				$where ['status'] = "上报评审会";
				break;
			case "6" :
				$where ['status'] = "材料补正";
				break;
			case "7" :
				$where ['status'] = "通过";
				break;
			case "8" :
				$where ['status'] = "公示";
				break;
			case "9" :
				$where ['status'] = "公告";
				break;
			case "10" :
				$where ['status'] = "发证";
				break;
		}
		// 默认刷新页面
		if (empty ( $pg ) || ! is_numeric ( $pg ) || $pg <= 0)
			$pg = 1;
		$list = $service->get_list ( $pg, 10, $where, array (
				'id' => 'desc' 
		) );
		
		// 获取分类数量
		$tct_where = $where;
		unset ( $tct_where ['status'] );
		$ret->tct = $service->get_record_count ( $tct_where );
		$tjcs_where = $where;
		$where ['status'] = "提交初审";
		$ret->tjcs_ct = $service->get_record_count ( $tjcs_where );
		$cstg_where = $where;
		$cstg_where ['status'] = "初审通过";
		$ret->cstg_ct = $service->get_record_count ( $cstg_where );
		$csth_where = $where;
		$csth_where ['status'] = "初审退回";
		$ret->csth_ct = $service->get_record_count ( $csth_where );
		$yjsh_where = $where;
		$yjsh_where ['status'] = "原件审核";
		$ret->yjsh_ct = $service->get_record_count ( $yjsh_where );
		
		$sbpsh_where = $where;
		$sbpsh_where ['status'] = '上报评审会';
		$ret->sbpsh_ct = $service->get_record_count ( $sbpsh_where );
		$clbz_where = $where;
		$clbz_where ['status'] = "材料补正";
		$ret->clbz_ct = $service->get_record_count ( $clbz_where );
		$tg_where = $where;
		$tg_where ['status'] = "通过";
		$ret->tg_ct = $service->get_record_count ( $tg_where );
		$gs_where = $where;
		$gs_where ['status'] = "公示";
		$ret->gs_ct = $service->get_record_count ( $gs_where );
		$gg_where = $where;
		$gg_where ['status'] = "公告";
		$ret->gg_ct = $service->get_record_count ( $gg_where );
		$fz_where = $where;
		$fz_where ['status'] = "发证";
		$ret->fz_ct = $service->get_record_count ( $fz_where );
		
		$totalCount = $service->get_record_count ( $where );
		$page_count = 1;
		if ($totalCount > 0)
			$page_count = ceil ( $totalCount / 10.0 );
		if ($list === false) {
			$ret->status = 500;
			$ret->data = "未找到匹配数据";
		} else {
			$ret->status = 200;
			$ret->data = $list;
			$ret->page_count = $page_count;
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_3A() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_3A' );
	}
	
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_3B() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_3B' );
	}
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_2C() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_2C' );
	}
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_2A() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_2A' );
	}
	
	/**
	 *
	 * @see 资质审核管理-三级资质审查列表
	 */
	function actionList_2B() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_2B' );
	}
	
	/**
	 *
	 * @see 资质审核管理-二级资质审查列表
	 */
	function actionList_2() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'list_2' );
	}
	
	/**
	 *
	 * @see 三级资质ajax列表
	 */
	function actionAjax_list_2_list() {
		$ret = new stdClass ();
		$ret->status = 401;
		
		if (Yii::app ()->user->isGuest) {
			$ret->data = "请登录";
			echo json_encode ( $ret );
			Yii::app ()->end ();
		}
		$service = new ReceiptEntity ();
		$pg = $_GET ['page'];
		$name = $_GET ['c_unit'];
		
		$where = array (
				'deleted' => 0,
				' ' => "[code] (content='二级延续' or content='三级升二级' or content='二级升一级') [code]" 
		);
		if ($name != "") {
			$where ['c_unit'] = "[code] like '%$name%' [code]";
		}
		$tb = $_GET ['tb'];
		switch ($tb) {
			default :
				break;
			case "1" :
				$where ['status'] = "提交初审";
				break;
			case "2" :
				$where ['status'] = "初审通过";
				break;
			case "3" :
				$where ['status'] = "初审退回";
				break;
			case "4" :
				$where ['status'] = "原件审核";
				break;
			case "5" :
				$where ['status'] = "上报评审会";
				break;
			case "6" :
				$where ['status'] = "材料补正";
				break;
			case "7" :
				$where ['status'] = "通过";
				break;
			case "8" :
				$where ['status'] = "上报省建设厅";
				break;
			case "9" :
				$where ['status'] = "证书登记";
				break;
		}
		// 默认刷新页面
		if (empty ( $pg ) || ! is_numeric ( $pg ) || $pg <= 0)
			$pg = 1;
		$list = $service->get_list ( $pg, 10, $where, array (
				'id' => 'desc' 
		) );
		
		// 获取分类数量
		$tct_where = $where;
		unset ( $tct_where ['status'] );
		$ret->tct = $service->get_record_count ( $tct_where );
		$tjcs_where = $where;
		$where ['status'] = "提交初审";
		$ret->tjcs_ct = $service->get_record_count ( $tjcs_where );
		$cstg_where = $where;
		$cstg_where ['status'] = "初审通过";
		$ret->cstg_ct = $service->get_record_count ( $cstg_where );
		$csth_where = $where;
		$csth_where ['status'] = "初审退回";
		$ret->csth_ct = $service->get_record_count ( $csth_where );
		$yjsh_where = $where;
		$yjsh_where ['status'] = "原件审核";
		$ret->yjsh_ct = $service->get_record_count ( $yjsh_where );
		
		$sbpsh_where = $where;
		$sbpsh_where ['status'] = '上报评审会';
		$ret->sbpsh_ct = $service->get_record_count ( $sbpsh_where );
		$clbz_where = $where;
		$clbz_where ['status'] = "材料补正";
		$ret->clbz_ct = $service->get_record_count ( $clbz_where );
		$tg_where = $where;
		$tg_where ['status'] = "通过";
		$ret->tg_ct = $service->get_record_count ( $tg_where );
		$sbsjst_where = $where;
		$sbsjst_where ['status'] = "上报省建设厅";
		$ret->sbsjst_ct = $service->get_record_count ( $sbsjst_where );
		$zsdj_where = $where;
		$zsdj_where ['status'] = "证书登记";
		$ret->zsdj_ct = $service->get_record_count ( $zsdj_where );
		
		$totalCount = $service->get_record_count ( $where );
		$page_count = 1;
		if ($totalCount > 0)
			$page_count = ceil ( $totalCount / 10.0 );
		if ($list === false) {
			$ret->status = 0;
			$ret->data = "未找到匹配数据";
		} else {
			$ret->status = 1;
			$ret->data = $list;
			$ret->page_count = $page_count;
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 资质审核管理-三级/二级资质审查列表-增加
	 */
	function actionAdd() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'add' );
	}
	/**
	 *
	 * @see 2A 在线审查
	 */
	function action2A() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( "2A", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 2B 现在审查
	 */
	function action2B() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( "2B", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 2C 现在审查
	 */
	function action2C() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( "2C", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 3A 在线审查
	 */
	function action3A() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( "3A", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 3B在线审查
	 */
	function action3B() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( "3B", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 二级审查详情
	 */
	function actionShow_2() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( "show_2", array (
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 三级审查详情
	 */
	function actionShow_3() {
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( "show_3", array (
				'model' => $model 
		) );
	}
	
	/**
	 *
	 * @see 收件登记 添加
	 */
	function actionAjax_receipt_add() {
		$ret = new stdClass ();
		$ret->status = 401;
		$linkman = $_POST ['linkman'];
		$phone = $_POST ['phone'];
		$content = $_POST ['content'];
		$sd_unit = $_POST ['sd_unit'];
		$material = $_POST ['material'];
		$sj_time = $_POST ['sj_time'];
		$fld = array (
				'linkman' => $linkman,
				'phone' => $phone,
				'content' => $content,
				'deleted' => 0,
				'add_time' => date ( 'Y-m-d H:i:s', time () ),
				'sd_time' => $sj_time,
				'sd_unit' => $sd_unit,
				'code_str' => date ( 'Ymd', time () ) . randstr ( 4, 'NUMBER' ),
				'material' => $material,
				'status' => '提交初审' 
		);
		$service = new ReceiptEntity ();
		$result = $service->insert ( $fld );
		if (is_numeric ( $result ) && $result > 0) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 500;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	/**
	 *
	 * @see 收件登记 编辑
	 */
	function actionAjax_receipt_editor() {
		$ret = new stdClass ();
		$ret->status = 401;
		$linkman = $_POST ['linkman'];
		$phone = $_POST ['phone'];
		$content = $_POST ['content'];
		$sd_unit = $_POST ['sd_unit'];
		$material = $_POST ['material'];
		$sj_time = $_POST ['sj_time'];
		$id = $_POST ['id'];
		$fld = array (
				'linkman' => $linkman,
				'phone' => $phone,
				'content' => $content,
				'deleted' => 0,
				'sd_time' => $sj_time,
				'sd_unit' => $sd_unit,
				'material' => $material,
				'status' => '提交初审' 
		);
		$service = new ReceiptEntity ();
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 500;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see ajax 删除收件登记信息
	 */
	function actionAjax_receipt_delete() {
		$ret = new stdClass ();
		$ret->status = 401;
		
		if (Yii::app ()->user->isGuest) {
			$ret->data = "请登录";
			echo json_encode ( $ret );
			Yii::app ()->end ();
		}
		if (isset ( $_POST ['id'] ) && is_numeric ( $_POST ['id'] )) {
			$id = $_POST ['id'];
			$service = new ReceiptEntity ();
			$result = $service->delete_bogus ( $id );
			if ($result === true) {
				$ret->status = 200;
				$ret->data = "操作成功";
			} else {
				$ret->status = 500;
				$ret->data = "操作失败";
			}
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 收件登记列表
	 */
	function actionAjax_receipt_list() {
		$ret = new stdClass ();
		$ret->status = 401;
		/*
		 * if (Yii::app ()->user->isGuest) {
		 * $ret->data = "请登录";
		 * echo json_encode ( $ret );
		 * Yii::app ()->end ();
		 * }
		 */
		$service = new ReceiptEntity ();
		$pg = $_GET ['page'];
		$name = $_GET ['name'];
		
		$where = array (
				'deleted' => 0 
		);
		if ($name != "") {
			$where ['phone'] = "[code] like '%$name%' [code]";
		}
		// 默认刷新页面
		if (empty ( $pg ) || ! is_numeric ( $pg ) || $pg <= 0)
			$pg = 1;
		$list = $service->get_list ( $pg, 10, $where, array (
				'id' => 'desc' 
		) );
		$totalCount = $service->get_record_count ( $where );
		$page_count = 1;
		if ($totalCount > 0)
			$page_count = ceil ( $totalCount / 10.0 );
		if ($list === false) {
			$ret->status = 0;
			$ret->data = "未找到匹配数据";
		} else {
			$ret->status = 1;
			$ret->data = $list;
			$ret->page_count = $page_count;
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 资质审核管理-三级/二级资质审查列表-证书
	 */
	function actionQualification() {
		$id = $_GET ['id']; // 资质审查ID
		$t = $_GET ['ty'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		$this->render ( 'qualification', array (
				'id' => $id,
				'ty' => $t,
				'model' => $model 
		) );
	}
	
	/**
	 *
	 * @see 资质审核管理-收件登记列表
	 */
	function actionReceipt() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'receipt' );
	}
	
	/**
	 *
	 * @see 资质审核管理-收件登记列表-增加
	 */
	function actionReceiptAdd() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$dicService = new SysDictionaryEntity ();
		// 区域列表
		$data = $dicService->get_list ( - 1, - 1, array (
				'sys_dict_type_id' => 5,
				'deleted' => 0 
		), array (
				"sys_order_num" => 'desc' 
		) );
		$this->render ( 'receiptAdd', array (
				'data' => $data 
		) );
	}
	
	/**
	 *
	 * @see 资质审核管理-收件登记列表-编辑
	 */
	function actionReceiptEdit() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		if ($model === false || is_array ( $model ) === false || count ( $model ) === 0)
			exit ( "参数错误" );
		$dicService = new SysDictionaryEntity ();
		// 区域列表
		$data = $dicService->get_list ( - 1, - 1, array (
				'sys_dict_type_id' => 5,
				'deleted' => 0 
		), "sys_order_num" );
		$this->render ( 'receiptEdit', array (
				'data' => $data,
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 资质审核管理-收件登记列表-编辑
	 */
	function actionReceiptDetail() {
		if (Yii::app ()->user->isGuest) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$id = $_GET ['id'];
		$service = new ReceiptEntity ();
		$model = $service->get ( $id );
		if ($model === false || is_array ( $model ) === false || count ( $model ) === 0)
			exit ( "参数错误" );
		$dicService = new SysDictionaryEntity ();
		// 区域列表
		$data = $dicService->get_list ( - 1, - 1, array (
				'sys_dict_type_id' => 5,
				'deleted' => 0 
		), "sys_order_num" );
		$this->render ( 'receiptdetail', array (
				'data' => $data,
				'model' => $model 
		) );
	}
	/**
	 *
	 * @see 原件审核
	 */
	function actionAjax_receipt_yjsh() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '原件审核' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 上报评审会
	 */
	function actionAjax_receipt_sbpsh() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '上报评审会' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see '材料补正
	 */
	function actionAjax_receipt_clbz() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '材料补正' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	/**
	 *
	 * @see 通过
	 */
	function actionAjax_receipt_tg() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '通过' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 公示
	 */
	function actionAjax_receipt_gs() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '公示' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 公告
	 */
	function actionAjax_receipt_gg() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '公告' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 在线审查 Ajax请求处理
	 */
	function actionAjax_online_zxsc() {
		$ret = new stdClass ();
		$ret->status = 401;
		$ty = $_POST ['ty'];
		$content = $_POST ['content'];
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = null;
		if ($ty == "A") {
			$fld = array (
					"cxamine_a_str" => $content 
			);
		} else if ($ty == "B") {
			$fld = array (
					"cxamine_B_str" => $content 
			);
		} else if ($ty == "C") {
			$fld = array (
					"cxamine_B_str" => $content 
			);
		} else {
			exit ( "参数错误" );
		}
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 通过
	 */
	function actionAjax_receipt_sbsjst() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$service = new ReceiptEntity ();
		$fld = array (
				'status' => '上报省建设厅' 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	/**
	 *
	 * @see 通过
	 */
	function actionAjax_receipt_zsdj() {
		$ret = new stdClass ();
		$ret->status = 401;
		$id = $_POST ['id'];
		$certificate_no = $_POST ['certificate_no'];
		$certificate_time = $_POST ['certificate_time'];
		$maturity_time = $_POST ['maturity_time'];
		$service = new ReceiptEntity ();
		$t = $_POST ['ty'];
		$status = "发证";
		if ($ty == "2")
			$status = "证书登记";
		$fld = array (
				'status' => '证书登记',
				'certificate_no' => $certificate_no,
				'certificate_time' => $certificate_time,
				'maturity_time' => $maturity_time 
		);
		$result = $service->update ( $fld, array (
				'id' => $id 
		) );
		if ($result === true) {
			$ret->status = 200;
			$ret->data = "操作成功";
		} else {
			$ret->status = 200;
			$ret->data = "操作失败";
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 资质证书
	 */
	function actionAptitude() {
		if (Yii::app ()->user->isGuest || is_array ( Yii::app ()->session ['user'] ) === false) {
			$this->redirect ( Yii::app ()->user->loginUrl );
		}
		$this->render ( 'aptitude_list' );
	}
	/**
	 *
	 * @see 资质证书ajax列表
	 */
	function actionAjax_aptitude_list() {
		$ret = new stdClass ();
		$ret->status = 401;
		/*
		 * if (Yii::app ()->user->isGuest) {
		 * $ret->data = "请登录";
		 * echo json_encode ( $ret );
		 * Yii::app ()->end ();
		 * }
		 */
		$service = new ReceiptEntity ();
		$pg = $_GET ['page'];
		$name = $_GET ['name'];
		
		$where = array (
				'deleted' => 0,
				' ' => "[code] (status='发证' or status='证书登记') [code]" 
		);
		if ($name != "") {
			$where ['phone'] = "[code] like '%$name%' [code]";
		}
		// 默认刷新页面
		if (empty ( $pg ) || ! is_numeric ( $pg ) || $pg <= 0)
			$pg = 1;
		$list = $service->get_list ( $pg, 10, $where, array (
				'id' => 'desc' 
		) );
		$totalCount = $service->get_record_count ( $where );
		$page_count = 1;
		if ($totalCount > 0)
			$page_count = ceil ( $totalCount / 10.0 );
		if ($list === false) {
			$ret->status = 0;
			$ret->data = "未找到匹配数据";
		} else {
			$ret->status = 1;
			$ret->data = $list;
			$ret->page_count = $page_count;
		}
		echo json_encode ( $ret );
	}
}
